//
//  CompanyInfoModel.m
//  Btpin
//
//  Created by Vic on 2019/3/19.
//  Copyright © 2019 Vic. All rights reserved.
//

#import "CompanyInfoModel.h"

@implementation CompanyInfoModel

- (void)setValuesForKeysWithDictionary:(NSDictionary<NSString *,id> *)keyedValues {
    self.id = [UIToolsControl dataAnalysis:keyedValues[@"id"]];
    self.name = [UIToolsControl dataAnalysis:keyedValues[@"name"]];
    self.full_name = [UIToolsControl dataAnalysis:keyedValues[@"full_name"]];
    self.logo = [UIToolsControl dataAnalysis:keyedValues[@"logo"]];
    self.scale_cn = [UIToolsControl dataAnalysis:keyedValues[@"scale_cn"]];
    self.nature_cn = [UIToolsControl dataAnalysis:keyedValues[@"nature_cn"]];
    self.finance_cn = [UIToolsControl dataAnalysis:keyedValues[@"finance_cn"]];
    self.trade_cn = [UIToolsControl dataAnalysis:keyedValues[@"trade_cn"]];
    self.district_cn = [UIToolsControl dataAnalysis:keyedValues[@"district_cn"]];
    self.tags = [NSMutableArray arrayWithCapacity:0];
    if (keyedValues[@"tags"] && [keyedValues[@"tags"] count]) {
        for (NSString *str in keyedValues[@"tags"]) {
            [self.tags addObject:str];
        }
    }
    self.descriptionStr = [UIToolsControl dataAnalysis:keyedValues[@"description"]];
    self.website = [UIToolsControl dataAnalysis:keyedValues[@"website"]];
    self.audit = [UIToolsControl dataAnalysis:keyedValues[@"audit"]];
    self.cert_pic = [UIToolsControl dataAnalysis:keyedValues[@"cert_pic"]];
    self.show_cert = [UIToolsControl dataAnalysis:keyedValues[@"show_cert"]];
    self.telephone = [UIToolsControl dataAnalysis:keyedValues[@"telephone"]];
    self.show_telephone = [UIToolsControl dataAnalysis:keyedValues[@"show_telephone"]];
    self.landline_tel = [UIToolsControl dataAnalysis:keyedValues[@"landline_tel"]];
    self.show_landline_tel = [UIToolsControl dataAnalysis:keyedValues[@"show_landline_tel"]];
    self.email = [UIToolsControl dataAnalysis:keyedValues[@"email"]];
    self.show_email = [UIToolsControl dataAnalysis:keyedValues[@"show_email"]];
    self.address = [UIToolsControl dataAnalysis:keyedValues[@"address"]];
    self.map_x = [UIToolsControl dataAnalysis:keyedValues[@"map_x"]];
    self.map_y = [UIToolsControl dataAnalysis:keyedValues[@"map_y"]];
    self.map_zoom = [UIToolsControl dataAnalysis:keyedValues[@"map_zoom"]];
    
    self.focus_status = [UIToolsControl dataAnalysis:keyedValues[@"focus_status"]];
    self.auth_medal = [UIToolsControl dataAnalysis:keyedValues[@"auth_medal"]];
    
    self.job_num = [UIToolsControl dataAnalysis:keyedValues[@"job_num"]];
    self.newjob = [[NewOrHotJobModel alloc] init];
    if (keyedValues[@"new_job"] && [keyedValues[@"new_job"] isKindOfClass:[NSDictionary class]]) {
        [self.newjob setValuesForKeysWithDictionary:keyedValues[@"new_job"]];
    }
    
    if (self.job_num && ([self.job_num integerValue]>0)) {
        self.listCellHeight = CompanyCellHeight;
    } else {
        self.listCellHeight = 135*Scale;
    }
    if (self.tags && self.tags.count) {
        self.listCellHeight = self.listCellHeight;
    } else {
        self.listCellHeight = self.listCellHeight-40*Scale;
    }
    self.listCellHeight -= ScalePS(3);
    
    self.descriptionHeight = 0;
    self.partHeight = 0;
    self.allHeight = 0;
    if (self.descriptionStr && self.descriptionStr.length) {
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        [paragraphStyle setLineSpacing:LineSpacingHeight];
        NSInteger textHeight = ceil([self.descriptionStr boundingRectWithSize:CGSizeMake(WIDTH-30*Scale, MAXFLOAT) options:(NSStringDrawingUsesFontLeading|NSStringDrawingTruncatesLastVisibleLine|NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:Font(Font_13), NSParagraphStyleAttributeName:paragraphStyle} context:nil].size.height)+1;
        self.descriptionHeight = textHeight;
        
//        self.partHeight = ((self.descriptionHeight>100*Scale)?(140*Scale):(self.descriptionHeight+15*Scale))+(([self.show_cert integerValue])?110*Scale:40*Scale)+782*Scale+ScalePS(60);
//        self.allHeight = (self.descriptionHeight+10.5*Scale)+(([self.show_cert integerValue])?110*Scale:40*Scale)+782*Scale+ScalePS(60);
        self.partHeight = ((self.descriptionHeight>100*Scale)?(140*Scale):(self.descriptionHeight+15*Scale))+(([self.show_cert integerValue])?110*Scale:40*Scale)+782*Scale;
        self.allHeight = (self.descriptionHeight+10.5*Scale)+(([self.show_cert integerValue])?110*Scale:40*Scale)+782*Scale;
    } else {
//        self.partHeight = 10*Scale+(([self.show_cert integerValue])?110*Scale:40*Scale)+782*Scale+ScalePS(60);
//        self.allHeight = 10*Scale+(([self.show_cert integerValue])?110*Scale:40*Scale)+782*Scale+ScalePS(60);
        self.partHeight = 10*Scale+(([self.show_cert integerValue])?110*Scale:40*Scale)+782*Scale;
        self.allHeight = 10*Scale+(([self.show_cert integerValue])?110*Scale:40*Scale)+782*Scale;
    }
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key {
    
}

- (id)copyWithZone:(NSZone *)zone {
    CompanyInfoModel *model = [[[self class] allocWithZone:zone] init];
    model.id = self.id;
    model.name = self.name;
    model.full_name = self.full_name;
    model.logo = self.logo;
    model.scale_cn = self.scale_cn;
    model.nature_cn = self.nature_cn;
    model.finance_cn = self.finance_cn;
    model.trade_cn = self.trade_cn;
    model.district_cn = self.district_cn;
    model.tags = [NSMutableArray arrayWithCapacity:0];
    [model.tags addObjectsFromArray:self.tags];
    model.descriptionStr = self.descriptionStr;
    model.website = self.website;
    model.audit = self.audit;
    model.cert_pic = self.cert_pic;
    model.show_cert = self.show_cert;
    model.telephone = self.telephone;
    model.show_telephone = self.show_telephone;
    model.landline_tel = self.landline_tel;
    model.show_landline_tel = self.show_landline_tel;
    model.email = self.email;
    model.show_email = self.show_email;
    model.address = self.address;
    model.map_x = self.map_x;
    model.map_y = self.map_y;
    model.map_zoom = self.map_zoom;
    model.descriptionHeight = self.descriptionHeight;
    model.partHeight = self.partHeight;
    model.allHeight = self.allHeight;
    
    model.focus_status = self.focus_status;
    model.auth_medal = self.auth_medal;
    
    model.job_num = self.job_num;
    model.newjob = [self.newjob copy];
    
    return model;
}

@end
